package frame

import (
	"encoding/json"
	"github.com/beego/beego/v2/core/logs"
	"github.com/beego/beego/v2/server/web"
)

func init() {
	//logger.InitLogger()

	logConf := make(map[string]interface{})
	maxlines, lerr := web.AppConfig.Int("Log::MaxLines")
	if lerr != nil {
		maxlines = 1000
	}
	logConf["maxlines"] = maxlines

	logConf["filename"] = web.AppConfig.DefaultString("Log::LogPath", "")

	level, _ := web.AppConfig.Int("Log::LogLevel")
	logConf["level"] = level

	maxdays, lerr := web.AppConfig.Int64("Log::MaxDays")
	if lerr != nil {
		maxdays = 10
	}
	logConf["maxdays"] = maxdays

	color, lerr := web.AppConfig.Bool("Log::Color")
	if lerr != nil {
		color = true
	}
	logConf["color"] = color

	daily, lerr := web.AppConfig.Bool("Log::Daily")
	if lerr != nil {
		daily = true
	}
	logConf["daily"] = daily

	confStr, err := json.Marshal(logConf)
	if err != nil {
		println("marshal failed,err:", err)
		return
	}
	adapter := web.AppConfig.DefaultString("Log::LogAdapter", "console")
	//err1 := logs.SetLogger(adapter, string(confStr))
	err1 := logs.SetLogger(adapter, string(confStr))
	if err1 != nil {
	}
	logs.SetLogFuncCall(true)

}
